# This work is licensed under the MIT license.
# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# LCD Example
#
# Note: To run this example you will need a LCD Shield for your OpenMV Cam.
#
# The LCD Shield allows you to view your OpenMV Cam's frame buffer on the go.

import sensor
import display
import   time
sensor.reset()  # 初始化sensor
sensor.set_pixformat(sensor.RGB565)  # or sensor.GRAYSCALE
sensor.set_framesize(sensor.HVGA)  # 128x160大小的特定液晶屏。
sensor.set_vflip(True) # 垂直翻转
sensor.set_hmirror(True)
sensor.set_transpose(True)
# Initialize the lcd screen.
# Note: A DAC or a PWM backlight controller can be used to control the
# backlight intensity if supported:
#  lcd = display.SPIDisplay(backlight=display.DACBacklight(channel=2))
#  lcd.backlight(25) # 25% intensity
# Otherwise the default GPIO (on/off) controller is used.
lcd = display.SPIDisplay(width =320,height =480,bgr=True,triple_buffer=False)
clock = time.clock() # 跟踪FPS帧率
while True:
    clock.tick() # 追踪两个snapshots()之间经过的毫秒数.
    image=sensor.snapshot()
    image.draw_cross(160,240,color=(0,255,0))
    s="fps:= {}".format(clock.fps())
    print(s)
    image.draw_string(280,460,s,color=(255,0,0),x_spacing =-4,\
                                        char_hmirror=True,\
                                        char_rotation=180,\
                                        string_rotation=-90,\
                                        scale=2)
    lcd.write(image)  # Take a picture and display the image.
